/*
* ========== Copyright Header Begin ==========================================
* 
* OpenSPARC T1 Processor File: cpu_interface.h
* Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* 
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* 
* The above named program is distributed in the hope that it will be 
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
* 
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* 
* ========== Copyright Header End ============================================
*/
////////////////////////////////////////////////////////////
//
// File: cpu_interface.h
//

#ifndef _CPU_INTERFACE_H
#define	_CPU_INTERFACE_H


#include <thread.h>
#include "mem.h"
#include "cpu_lib_intf.h"
#include "prioque.h"
#include "vtracer.h"


// This file contains interface for the cpu shared
// library module



// Cpu module may have a few cpu, each cpu may have
// a few cores, each core may have a few strands. 
// Cpu cores could run on separate threads 
// of the host machine.


// global vcpu table
extern Vcpu *g_vcpu[NCPU_MAX];
extern int   g_nvcpu_max; 

extern VCPU_ExInterface g_cpu_ex_intf;


// cofiguration parameters
int set_param ( int cpu_id, char *param_name ); 
int set_param ( char *name_value, VCPU_Config *config );
char *get_param ( int cpu_id, char *param_name );
void  set_default ( VCPU_Config &config );


extern bool_t	volatile    cpu_on[NCPU_MAX];
extern thread_t	volatile    cpu_thrd[NCPU_MAX];
extern bool_t   volatile    cpu_enabled[];

// Vcpu constructor routines
Vcpu* create_cpu 
(
    char *path,          // library path
    char *pconfig,       // config line with name=value pairs
    VCPU_ImpIntf *intf,  // cpu imported interface
    int version = 1      // cpu lib version number
);

Vcpu* create_cpu 
(
    char *path,               // library path
    VCPU_Config  &config_info,  // cpu config params
    VCPU_ImpIntf *intf,         // cpu imported interface
    int version = 1           // cpu lib version number
);


extern int cpu_set_breakpoint    ( int cpu_id,  VCPU_BpType type, uint64_t addr ); 
extern int cpu_remove_breakpoint ( int cpu_id,  VCPU_BpType type, uint64_t addr ); 

extern int disassemble ( uint32_t iw, uint64_t addr, char *line, int line_size);
extern int ui_read_regs (int argc, char **argv);
extern void print_current_pc();


/////////////////////////////////////////////////////////
//
// A mini tracer to output instructions to the ui console
//
class STracer : public VTracer
{
public:
  STracer (char *fname); 
  ~STracer();
  int attach(VTracer_SAM_intf * intf); 
  int instr ( VCPU_Instruction *i ); 
  int trap  ( VCPU_Trap *t );
  int tlb   ( VCPU_TLB *s );
  int async (VCPU_AsyncData *)	{ return 1; }
  int sync  (VCPU_Sync *)       { return 1; }
  int put_string(int cpuid, const char * str);

  FILE *stream; 
};


     
#endif  //  _CPU_INTERFACE_H
